/**
 * Created by Neville Kadwa.
 */

package org.shiftone.cdep.store;

import org.apache.log4j.Logger;
import org.shiftone.cdep.store.StoreException;
import org.shiftone.cdep.store.StoreManager;
import org.shiftone.cdep.store.StoreManagerFactory;
import junit.framework.TestCase;

public class StoreManagerTestCase extends TestCase
{

    public static final Logger LOG = Logger.getLogger(StoreManagerTestCase.class);


    public void testClass() throws Exception
    {
        StoreManager storeManager = StoreManagerFactory.getStoreManager();

        int importLocation = storeManager.setImportLocation("test");

        int testId = storeManager.setClass("org.package.test.TestPackage", null, Boolean.FALSE, Boolean.FALSE, null, new Integer(importLocation));

        int queryId = storeManager.getClass("org.package.test.TestPackage");

        assertEquals("class ids", queryId, testId);

        storeManager.dropClass("org.package.test.TestPackage");

        try
        {
            storeManager.dropClass(testId);

            assertTrue("Should have exception", false);
        }
        catch (StoreException sex) { }

        try
        {
            storeManager.dropClass("not.existent.sumptin");

            assertTrue("Should have exception", false);
        }
        catch (StoreException sex) { }
    }

    public void testMethods() throws Exception
    {
        StoreManager storeManager = StoreManagerFactory.getStoreManager();

        int importLocation = storeManager.setImportLocation("test");

        int classId = storeManager.setClass("org.testMethods.test1", null, Boolean.FALSE, Boolean.FALSE, null, new Integer(importLocation));

        int methodId = storeManager.setMethod(classId, "yoyo1", "yoo(java.lang.StringL)V");

        int testId = storeManager.getMethod(classId, "yoyo1", "yoo(java.lang.StringL)V");

        assertEquals(methodId, testId);

        storeManager.dropClass(classId);
    }

    public void testMethodCalls() throws Exception
    {
        StoreManager storeManager = StoreManagerFactory.getStoreManager();

        int importLocation = storeManager.setImportLocation("test");

        int classId = storeManager.setClass("org.testMethodCalls.test1", null, Boolean.FALSE, Boolean.FALSE, null, new Integer(importLocation));

        int method1Id = storeManager.setMethod(classId, "yoyo1", "yoo(java.lang.StringL)V");

        int method2Id = storeManager.setMethod(classId, "yoyo1", "yoo(java.lang.StringL)V");

        // Recursive call
        storeManager.setMethodCall(method1Id, method1Id);

        storeManager.setMethodCall(method1Id, method1Id);

        storeManager.setMethodCall(method1Id, method2Id);

        storeManager.dropClass(classId);

    }

}

/* EOF */
